//
//  LRJRecTravelDetailTableViewCell.m
//  BreadTravel
//
//  Created by 李润嘉 on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LRJRecTravelDetailTableViewCell.h"

@implementation LRJRecTravelDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}
- (void)createSubView
{
    
   
    self.photoImage = [[UIImageView alloc]init];
    self.photoImage.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.photoImage];
    [self.photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.top.mas_equalTo(@10);
        make.size.mas_equalTo(CGSizeMake(100, 100));
        
    }];
    
    UIImageView *triangleImage = [[UIImageView alloc] init];
    triangleImage.image = [UIImage imageNamed:@"feedcell_photo_cover.png"];
    [self.contentView addSubview: triangleImage];
    [triangleImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(self.photoImage.mas_bottom).offset(0);
        make.left.equalTo(self.photoImage.mas_left).offset(0);
        make.right.equalTo(self.photoImage.mas_right).offset(0);

        
    }];
    
    
    self.textlabel = [[UILabel alloc]init];
    self.textlabel.font = [UIFont systemFontOfSize:15];
//    self.textlabel.backgroundColor = [UIColor whiteColor];
    self.textlabel.numberOfLines = 0;
    [self.contentView addSubview:self.textlabel];
    [self.textlabel mas_makeConstraints:^(MASConstraintMaker *make) {
      
        make.left.mas_equalTo(@10);
        make.right.mas_equalTo(@-10);
        make.top.equalTo(self.photoImage.mas_bottom);
    }];
    
    
    
    
    self.clockImage = [[UIImageView alloc]init];
    self.clockImage.image = [UIImage imageNamed:@"clock_gray_big@2x.png"];
    [self.contentView addSubview:self.clockImage];
    
    
    self.loca_time = [[UILabel alloc]init];
    self.loca_time.font = [UIFont systemFontOfSize:13];
    self.loca_time.alpha = 0.6;
    [self.contentView addSubview:self.loca_time];
    
    
}

- (void)setWayModel:(LRJTravelDetailWaypointsModel *)wayModel
{
    CGSize myImageSize = [[self class] heightForImageModelWidth:wayModel.photoModel.w ModelHeight:wayModel.photoModel.h];
    [self.photoImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(@10);
        make.size.mas_equalTo(myImageSize);
        
    }];
    NSURL *url = [NSURL URLWithString:wayModel.photo];
    [self.photoImage sd_setImageWithURL:url placeholderImage:IMAGE];
    
    [self.textlabel mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@10);
        make.right.mas_equalTo(@-10);
        make.top.equalTo(self.photoImage.mas_bottom);
    }];
    
    [self.clockImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.textlabel.mas_bottom).offset(10);
        make.left.mas_equalTo(@10);
        
    }];
    [self.loca_time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.textlabel.mas_bottom).offset(8);
        make.left.equalTo(self.clockImage.mas_right);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@200);
    }];

    self.textlabel.text = wayModel.text;
    self.loca_time.text  =wayModel.local_time;
    
    
}
+(CGSize)heightForImageModelWidth:(CGFloat)width ModelHeight:(CGFloat)height
{
    CGSize size = CGSizeMake(WIDTH - 20 , height / width * (WIDTH - 20));
    return size;
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
